<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-stock__piggrowth}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-select v-model="dataForm.houseId" placeholder="猪舍" clearable>
            <el-option
                v-for="item in houses"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item class="pull-right" size="small">
          <el-radio-group v-model="display">
            <el-radio-button label="表格"></el-radio-button>
            <el-radio-button label="栏位"></el-radio-button>
          </el-radio-group>
        </el-form-item>
<!--        <el-form-item>-->
<!--          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-button v-if="$hasPermission('stock:piggrowth:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-button v-if="$hasPermission('stock:piggrowth:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>-->
<!--        </el-form-item>-->
        <!-- <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="introduceHandle()" type="success">{{ $t('introduce') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="transferHandle()" type="warning">{{ $t('transfer') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="leaveHandle()" type="info">{{ $t('leave') }}</el-button>
        </el-form-item> -->
      </el-form>
      <template v-if="display=='栏位'">
        <div v-for="house in houses" v-bind:key="house.id">
          <!-- <h4>{{ house.name }}</h4> -->
          <Grid type="1" :house_id="house.id"></Grid>
        </div>
      </template>
      <template v-if="display!='栏位'">
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%;">
  <!--        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
  <!--        <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
          <el-table-column prop="houseName" label="猪舍" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="grid" label="栏位" sortable="custom" header-align="center" align="center"></el-table-column>
  <!--        <el-table-column prop="groupNo" label="猪群编号" header-align="center" align="center"></el-table-column>-->
          <el-table-column prop="mounts" label="头数" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="sources" label="来源" sortable="custom" header-align="center" align="center">
            <template slot-scope="scope">
              {{ $getDictLabel("source", scope.row.sources) }}
            </template>
          </el-table-column>
          <!-- <el-table-column prop="inDate" label="进场日期" sortable="custom" header-align="center" align="center"></el-table-column> -->
          <el-table-column prop="agePlus" label="平均日龄" sortable="custom" header-align="center" align="center"></el-table-column>
  <!--        <el-table-column prop="monthAge" label="月龄" header-align="center" align="center"></el-table-column>-->
          <el-table-column prop="state" label="猪舍类型" header-align="center" align="center">
            <template slot-scope="scope">
              {{ $getDictLabel("growth_status", scope.row.state) }}
            </template>
          </el-table-column>
          <el-table-column prop="weight" label="总重" header-align="center" align="center"></el-table-column>
  <!--        <el-table-column prop="averageWeight" label="均重" header-align="center" align="center"></el-table-column>-->
          <!--  el-table-column prop="breed" label="品种" header-align="center" align="center">
            <template slot-scope="scope">
              {{ $getDictLabel("breed", scope.row.breed) }}
            </template>
          </el-table-column -->
          <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
  <!--        <el-table-column prop="tenantId" label="租户" header-align="center" align="center"></el-table-column>-->
  <!--        <el-table-column prop="creator" label="创建者" header-align="center" align="center"></el-table-column>-->
  <!--        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>-->
  <!--        <el-table-column prop="updater" label="更新者" header-align="center" align="center"></el-table-column>-->
  <!--        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>-->
          <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)" style="padding: 8px 4px;">详情</el-button>
              <!-- <el-button v-if="$hasPermission('stock:piggrowth:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button> -->
              <!-- <el-button v-if="$hasPermission('stock:piggrowth:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </template>
      <!-- 弹窗, 新增 / 修改 -->
      <add-upadte-modal v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-upadte-modal>
      <growth-introduce v-if="introduceVisible" ref="refGrowthIntroduce" @refreshDataList="getDataList" @uploadModal="showUpload"></growth-introduce>
      <growth-transfer v-if="transferVisible" ref="refGrowthTransfer" @refreshDataList="getDataList"></growth-transfer>
      <growth-leave v-if="leaveVisible" ref="refGrowthLeave" @refreshDataList="getDataList"></growth-leave>
      <!-- 弹窗, 上传文件 -->
      <upload v-if="uploadVisible" ref="upload"></upload>
    </div>
  </el-card>
</template>

<script>/* eslint-disable */
import mixinViewModule from '@/mixins/view-module'
import GrowthIntroduce from "@/views/modules/stock/growth/growth-introduce";
import GrowthTransfer from "@/views/modules/stock/growth/growth-transfer";
import GrowthLeave from "@/views/modules/stock/growth/growth-leave";
import Upload from "@/views/modules/oss/oss-uploadgrowth";
import AddUpadteModal from '@/views/modules/stock/growth/growth-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/stock/piggrowth/page',
        getDataListIsPage: true,
        exportURL: '/stock/piggrowth/export',
        deleteURL: '/stock/piggrowth',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      uploadVisible: false,
      introduceVisible: false,
      transferVisible: false,
      leaveVisible: false,
      houses:[],
      display: '',
    }
  },
  components: {
    'growth-introduce': GrowthIntroduce,
    'growth-transfer': GrowthTransfer,
    'growth-leave': GrowthLeave,
    Upload,AddUpadteModal
  },
  mounted() {
    this.getHouses()
  },
  methods: {
    introduceHandle (id) {
      this.introduceVisible = true
      this.$nextTick(() => {
        this.$refs.refGrowthIntroduce.dataForm.id = id
        this.$refs.refGrowthIntroduce.init()
      })
    },
    getHouses () {
      let that = this
      this.$http.get(`/basic/house/all`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.houses = []
        let tmp = {}
        res.data.forEach(function (house) {
          if (!tmp[house.id]) {
            tmp[house.id] = 1
            that.houses.push(house)
          }
        })
        console.table(that.houses)
      }).catch(() => {})
    },
    transferHandle (id) {
      this.transferVisible = true
      this.$nextTick(() => {
        this.$refs.refGrowthTransfer.dataForm.id = id
        this.$refs.refGrowthTransfer.init()
      })
    },
    leaveHandle (id) {
      this.leaveVisible = true
      this.$nextTick(() => {
        this.$refs.refGrowthLeave.dataForm.id = id
        this.$refs.refGrowthLeave.init()
      })
    },
    showUpload () {
      this.uploadVisible = true
      this.$nextTick(() => {
        this.$refs.upload.init()
      })
    }
  }
}
</script>
<style scoped>
.el-table /deep/ .el-button{
  padding: 8px 10px;
}
</style>
